# Maintainer: George Rawlinson <george@rawlinson.net.nz>
# Maintainer: Thore Bödecker <foxxx0@archlinux.org>

# This must be built against the version of dovecot being used,
# otherwise it will fail to load and thus work.
# Specify the version of dovecot to be used here:
_dcpkgver=2.3.20
# Make sure to bump pkgrel if changing this.

pkgname=dovecot-fts-xapian
_pkgname="${pkgname#dovecot-}"
_pkgver=1.5.5 # pacman's vercmp does not like alphabet characters without a dot prefix
pkgver=1.5.5
pkgrel=5
pkgdesc="Dovecot FTS plugin based on Xapian"
arch=('loong64' 'x86_64')
url="https://github.com/grosjo/fts-xapian"
license=('LGPL2.1')
depends=("dovecot=${_dcpkgver}" 'icu' 'xapian-core')
install="$pkgname.install"
source=("$pkgname-$pkgver.tar.gz::$url/archive/$_pkgver.tar.gz")
sha512sums=('229362207bfa7bb13b1ded4d8b2a2aef7a4a72306e140dc4bd5778991220b27d296ca3659993856f83c80c437f7feadebad1e3ac06f8120a6e45b69f6dbb1ecb')
b2sums=('b8e86b3655a6b7291961cfbd39d6ef93ab2e2fbb049e97ebd07b473eb5fc5ecf91950343adfa9c267791442d581ebea47416d8e674d7f3019091fbd69b6e60f1')

build() {
  cd "$_pkgname-$_pkgver"
  autoreconf -vi
  ./configure \
    --prefix=/usr \
    --with-dovecot=/usr/lib/dovecot

  make

  # generate systemd unit files
  mkdir build
  sed "s:@@prefix@@:/usr/bin:" contrib/systemd/dovecot-fts-optimize.service.in \
    > build/dovecot-fts-optimize.service
  sed "s:@@index_frequency@@:daily:" contrib/systemd/dovecot-fts-optimize.timer.in \
    > build/dovecot-fts-optimize.timer
}

package() {
  cd "$_pkgname-$_pkgver"

  make DESTDIR="$pkgdir" install

  # documentation
  install -vDm644 -t "$pkgdir/usr/share/doc/$pkgname" README.md

  # systemd integration
  install -vDm644 -t "$pkgdir/usr/lib/systemd/system" \
    build/dovecot-fts-optimize.{service,timer}
}
